package cn.gmcx.lazy.izze.controller;


import cn.gmcx.lazy.izze.pojo.Fans;
import cn.gmcx.lazy.izze.pojo.ToDo;
import cn.gmcx.lazy.izze.service.IFansService;
import cn.gmcx.lazy.izze.service.IToDoService;
import cn.gmcx.lazy.izze.utils.Result;
import cn.gmcx.lazy.izze.utils.ToDoMessage;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author GMCX
 * @since 2024-07-02
 */
@RestController
@RequestMapping("/todo")
public class ToDoController {
    @Autowired
    private IToDoService service;
    @Autowired
    private IFansService fansService;

    @GetMapping("/todo_select_userid")
    public Result getToDoListById(@RequestParam Integer userId) {
        List<ToDo> toDoList = service.getToDoList(userId);
        return Result.success(toDoList);
    }

    @PostMapping("/todo_dispose")
    public Result DisposeToDo(@RequestParam(name = "id") Integer toDoId, Integer masterId, Integer followId, Integer status) {
        Fans master = new Fans();
        master.setFollowerId(masterId);
        master.setFolloweeId(followId);
        ToDo toDo = new ToDo();
        toDo.setId(toDoId);
        toDo.setStatus(status);
        boolean b = service.updateById(toDo);
        if (b) {
            if (status == 1) {
                fansService.saveFans(master);
            }
            service.addToDo(masterId, ToDoMessage.Friend_SUCCESS, followId, 0);
            return new Result(200, "已处理");
        }
        return new Result(500, "处理失败");
    }

    @PostMapping("/todo_dispose_NF")
    public Result DisposeToDo2(@RequestParam(name = "id") Integer toDoId, Integer masterId, Integer status) {
        ToDo toDo = new ToDo();
        toDo.setId(toDoId);
        toDo.setStatus(status);
        boolean b = service.updateById(toDo);
        if (b) {
            if (status == 1){
                service.addToDoSuccess(masterId, ToDoMessage.Friend_SUCCESS);
            }
            return new Result(200, "已处理");
        }
        return new Result(500, "处理失败");
    }

    @PostMapping("/todo_dispose_know")
    public Result DisposeKnow(@RequestParam(name = "id") Integer toDoId,Integer masterId){
        int b = service.DisposeKnow(toDoId, masterId, 1);
        if (b!=0){
            return new Result(200,"已处理");
        }
        return new Result(500,"系统出错");
    }

//    @PostMapping("/todo_add")
//    public Result addToDo(Integer masterId,String message,@RequestParam(required = false) Integer followId){
//        service.addToDo(masterId,message,followId);
//        return null;
//    }
}
